package org.eztouch.common.mybatis;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 拦截设置本地线程变量
 */
@Aspect
@Component
public class DataSourceAop {
	private static final Logger log = LoggerFactory.getLogger(DataSourceAop.class);
	
//	@Before("execution(* org.eztouch.*.mapper..*.select*(..)) || execution(* org.eztouch.*.mapper..*.get*(..))")
	@Before("execution(* org.eztouch.*.facade..*.select*(..)) || execution(* org.eztouch.*.facade..*.get*(..))")
    public void setReadDataSourceType() {
        DataSourceContextHolder.read();
        log.info("dataSource切换到：Read");
    }

    @Before("execution(* org.eztouch.*.facade..*.insert*(..)) || execution(* org.eztouch.*.facade..*.update*(..))")
    public void setWriteDataSourceType() {
        DataSourceContextHolder.write();
        log.info("dataSource切换到：write");
    }
}
